package com.mumu.studykotlin

import com.mumu.studykotlin.gra.FunctionDemo
import org.junit.Test
import kotlin.math.PI

/**
 *edie create on 2019/8/1
 *
 */
class FunctionDemoTest {
    @Test
    fun _test() {
        val result = add(3, 5)
        println("结果是$result")
        println(result)

        val demo = FunctionDemo()
        val add = demo.add(3, 5)
        val b = demo.b
        val c = demo.c(3, 5)
        val d = demo.d

        println(b)
        println(c)
        println(d)
    }

    private fun add(a: Int, b: Int): Int {
        return a + b
    }

    var add1 = { a: Int, b: Int -> a + b }
    var add2: (Int, Int) -> Int = { a, b -> a + b }


    @Test
    fun _default() {
        val area = area(r = 4f)
        println(area)

        val jjjj = jjjj(r = "你好")
        println(jjjj)


    }

    fun area(pi: Float = 3.14f, r: Float): Float {
        return pi * r
    }

    fun perimeter(pi: Float = 3.14f, r: Float, d: Float) = {
        j(pi, r)
    }

    val j = { pi: Float, r: Float -> pi * r }
    val jj: (Float, Float) -> Float = { pi, r -> pi * r }
    val jjj: (pi: Float, r: Float) -> String = { pi, r -> (pi * r).toString() + "我其实是个字符串" }

    fun jjjj(pi: Float = 3.14f, r: String): String {
        return "我其实是个字符串--$r--$pi"
    }

    //递归
    @Test
    fun _digui() {
        val digui = diguijia(0, 1000000)
        println(digui)
    }

    fun digui(i: Int): Int {
        return if (i == 1) 1 else i * digui(i - 1)
    }

    tailrec fun diguijia(result: Int, i: Int): Int {
        return if (i == 0) result else diguijia(result+i, i-1 )
    }
}